package com.zzyl.nursing.service.impl;

import java.util.Arrays;
import java.util.List;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzyl.nursing.domain.NursingLevel;
import com.zzyl.nursing.dto.NursingLevelDto;
import com.zzyl.nursing.mapper.NursingLevelMapper;
import com.zzyl.nursing.service.INursingLevelService;
import com.zzyl.nursing.vo.NursingLevelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * 护理等级Service业务层处理
 * 
 * @author ljc
 * @date 2025-02-20
 */
@Service
public class NursingLevelServiceImpl extends ServiceImpl<NursingLevelMapper, NursingLevel> implements INursingLevelService {
    @Autowired
    private NursingLevelMapper nursingLevelMapper;

    /**
     * 查询护理等级
     *
     * @param id 护理等级主键
     * @return 护理等级
     */
    @Override
    public NursingLevelVo selectNursingLevelById(Long id)
    {
        NursingLevelVo nursingLevelVo = new NursingLevelVo();
        NursingLevel nursingLevel = nursingLevelMapper.selectById(id);
        BeanUtil.copyProperties(nursingLevel,nursingLevelVo);
        return nursingLevelVo;
    }

    /**
     * 查询护理等级列表
     *
     * @param nursingLevel 护理等级
     * @return 护理等级
     */
    @Override
    public List<NursingLevel> selectNursingLevelList(NursingLevel nursingLevel)
    {
        return nursingLevelMapper.selectNursingLevelList(nursingLevel);
    }

    /**
     * 新增护理等级
     * 
     * @param nursingLevelDto 护理等级
     * @return 结果
     */
    @Override
    public int insertNursingLevel(NursingLevelDto nursingLevelDto)
    {
        NursingLevel nursingLevel = BeanUtil.copyProperties(nursingLevelDto, NursingLevel.class);
        save(nursingLevel);
        return  1 ;
    }

    /**
     * 修改护理等级
     * 
     * @param nursingLevelDto 护理等级
     * @return 结果
     */
    @Override
    public int updateNursingLevel(NursingLevelDto nursingLevelDto)
    {
        NursingLevel nursingLevel = BeanUtil.copyProperties(nursingLevelDto, NursingLevel.class);
        return updateById(nursingLevel)? 1 : 0;
    }

    /**
     * 批量删除护理等级
     * 
     * @param ids 需要删除的护理等级主键
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deleteNursingLevelByIds(Long[] ids)
    {
        return removeBatchByIds(Arrays.asList(ids))? 1 : 0;
    }

    /**
     * 删除护理等级信息
     * 
     * @param id 护理等级主键
     * @return 结果
     */
    @Override
    public int deleteNursingLevelById(Long id)
    {
        return removeById(id)? 1 : 0;
    }

    /**
     *  查询所有护理等级
     * @return
     */
    @Override
    public List<NursingLevelVo> listAll() {
        List<NursingLevel> list = list();
        List<NursingLevelVo> nursingLevelVos = BeanUtil.copyToList(list, NursingLevelVo.class);
        return nursingLevelVos ;
    }

    /**
     *  分页查询
     * @param nursingLevel
     * @return
     */
    @Override
    public List<NursingLevelVo> selectNursingLevelVoList(NursingLevel nursingLevel) {

        return nursingLevelMapper.selectNursingLevelVoList(nursingLevel);

    }
}
